<?php
namespace app\index\validate;

use think\Validate;

class Reg extends Validate
{
    protected $rule = [
	    ['first_name','require','please enter your first_name'],
	    ['surnames','require','please enter your surnames'],
            ['phone','require','please enter your phone number'],
            ['email','require|email','Please enter your email address|Your email address is not in the correct format, please enter again.'],
        
            ['level_id','require','Please choose a membership level'],
        
            ['addr1','require','Please enter an addr1'],
            ['city','require','Please enter a city'],
            ['country','require','please enter a country'],
        
            ['is_true','require','Please choose whether the data is true'],
            ['is_crime','require','Please choose whether is_crime'],
        
        
            ['account','require|alphaDash|unique:member','Please enter a valid username|The username contains invalid characters. You must specify a name that includes only letters  numbers, dashes and underscores.Please enter a different name. |Sorry! The username your entered already exists,please enter a new one.'],
	    ['password','require|password:1','Please confirm the password and enter again.'],
            ['config_password','require|confirm:password','Please confirm the password and enter again.|Your password and confirmation password do not match. Try again.'],
        
            
//            ['email','require|email','Please enter your email address|Your email address is not in the correct format, please enter again.'],
        
        
            ['password','require|password:1','Please confirm the password and enter again.'],
            ['config_password','require|confirm:password','Please confirm the password and enter again.|Your password and confirmation password do not match. Try again.'],
    ];

    protected $scene = [
        'reg'  =>  ['first_name','surnames','phone','email'],
        'reg2'  =>  ['level_id'],
        'reg3'  =>  ['addr1','city','country'],
        'reg4'  =>  ['is_true'],
        'reg5'  =>  ['account','password','config_password'],
        'reg6'  =>  ['email'],  //找回密码 
        'reg7'  =>  ['password','config_password'],  //修改密码
    ]; 
     
     
     
    protected function password($value){
        if($value){
            $exp = "/^(?![^a-zA-Z]+$)(?!\D+$).{9,25}$/";  
            if(preg_match($exp,$value)){  
                return true;  
            }else{  
                return 'Incorrect password format, please enter again.Your password must be at least nine characters long but no more than 25 characters and contains a combination of letters and numbers. ';  
            }  
        }
    }
    
    
    protected function is_identity($value){
        if($value){
            $exp = "/^\d{6}((1[89])|(2\d))\d{2}((0\d)|(1[0-2]))((3[01])|([0-2]\d))\d{3}(\d|X)$/i";  
            if(preg_match($exp,$value)){  
                return true;  
            }else{  
                return '身份证格式不正确';  
            }  
        }
    }
     
}